﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
using Standards.Model.Models;

namespace Standards.Data.EntityFramework.Configurations
{
    public class UsersConfiguration : EntityTypeConfiguration<UserDto>
    {
        public UsersConfiguration()
        {
            this.ToTable("Users");

            this.Property(u => u.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            this.Property(u => u.Name).HasMaxLength(200).IsRequired(); // TODO: check microsoft schema

            this.Property(u => u.IsActive).IsRequired();
            this.Property(u => u.IsAdmin).IsRequired();

            this.HasMany(u => u.Roles).WithMany(r => r.Users).Map(cfg => 
                {
                    cfg.ToTable("UsersInRoles");
                    cfg.MapLeftKey("RoleId");
                    cfg.MapRightKey("UserId");
                });
        }
    }
}